package com.czd.support.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.czd.base.model.Paginate;
import com.czd.support.common.Configuration;
import com.czd.support.model.Manager;
import com.czd.support.model.Reply;
import com.czd.support.service.ReplyService;

@Controller
@RequestMapping("/reply")
public class ReplyAction extends BaseController{
	@Autowired
	private ReplyService replyService;
	
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String list(Reply reply, HttpServletRequest request, Model model, @RequestParam(value = "pageNo", defaultValue = "1") int pageNo){
		Manager manager = this.getSesionUser(request);
		if(manager != null){
			reply.setPageSize(Configuration.getInstance().getDefault_page_size());
			reply.setPageNo(pageNo);
			Paginate paginate = replyService.queryForPage(reply);
			model.addAttribute("paginate", paginate);
			return "reply/list";
		}else{
			return "redirect:/login";
		}
	}
	
	@RequestMapping(value = "/{id}/delete", method = RequestMethod.GET)
	public String delete(@PathVariable int id, Model model){
		if(replyService.delete(id)){
			return "reply/list";
		}
		return error(model, "提示消息", "操作成功");
	}

}
